<?php
	class StringUtils {
		
		public static function toHTML($textToConvert) {
			return nl2br(htmlspecialchars($textToConvert));
		}
		
		public static function isEmpty($chaineATester) {
			return $chaineATester == null || $chaineATester == "";
		}
		
		public static function startsWith($haystack, $needle, $caseSensitive=true, $trim=false){
			if ($caseSensitive == false) {
				$haystack = strtoupper($haystack);
				$needle = strtoupper($needle);
			}
			
			if ($trim == true) {
				$haystack = trim($haystack);
			}
			
			$length = strlen($needle);
			return (substr($haystack, 0, $length) === $needle);
		}

		public static function endsWith($haystack, $needle){
			$length = strlen($needle);
			$start  = $length * -1; //negative
			return (substr($haystack, $start) === $needle);
		}
		
		public static function getArrayAsString($array) {
			$result = "";
			if (count($array) == 0) {
				return $result;
			}
			foreach ($array as $element) {
				$result = $result."$element,";
			}
			return $delcaract = substr($result,0,strlen($result)-1);
		}
		
		public static function getIdArrayAsString($array) {
			$result = "";
			if (count($array) == 0) {
				return $result;
			}
			foreach ($array as $element) {
				$result = $result."$element->id,";
			}
			return $delcaract = substr($result,0,strlen($result)-1);
		}
		
		public static function explodeString($separator, $string) {
			if (StringUtils::endsWith($string, $separator)) {
				$string = substr($string,0,strlen($string)-1);
			}
			if (strlen($string) == 0) {
				return Array();
			}
			return explode($separator, $string);
		}
	}
?>